﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Data;

namespace PJ.Business
{
    /// <summary>
    /// EntityService class
    /// </summary>
    /// <typeparam name="TIItem">Object to serve type</typeparam>
    /// <typeparam name="OD">Inner data object type</typeparam>
    /// <typeparam name="ODP">Inner data object provider type</typeparam>
    public abstract class ItemService<TIItem, OD, ODP> : EntityService<TIItem, OD, ODP>, IItemService<TIItem>
        where TIItem : class, IItem
        where OD : class, IItemData
        where ODP : class, IItemProvider<OD>
    {
        #region Constructor

        public ItemService(ODP dataService)
            : base(dataService)
        {
        }
        
        #endregion

        

        #region Interface implementation

        /// <summary>
        /// Searchs the Item that match the given criteria
        /// </summary>
        /// <param name="searchText">search criteria</param>
        /// <returns>Collection of Item global ids</returns>
        /// <exception cref="ArgumentNullException">If <paramref cref="searchText"/> is <see langref="null"/> or empty.</exception>
        public string[] Search(string searchText, GetDataMode mode)
        {
            return DataService.Search(searchText, mode);
        }



        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        public TIItem GetByName(string name, GetDataMode mode)
        {
            return CreateNewItem(DataService.GetByName(name, mode));
        }



        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="name">Item aliasName</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="aliasName"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given aliasName does not exist.</exception>
        public TIItem GetByAlias(string aliasName, GetDataMode mode)
        {
            return CreateNewItem(DataService.GetByAlias(aliasName, mode));
        }

        #endregion

        #region Interface override

        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        IItem IItemService.GetByName(string name, GetDataMode mode)
        {
            return GetByName(name, mode);
        }


        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="aliasName">Item aliasName</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="aliasName"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given aliasName does not exist.</exception>
        IItem IItemService.GetByAlias(string aliasName, GetDataMode mode)
        {
            return GetByAlias(aliasName, mode);
        }


        #endregion    
    }

}

